package learn;

/**
 * 用一个array 实现 一个queue
 */
public class MyQueue {
    public int size;
    public int len;
    public int[] value;
    public int pushIndex;
    public int pullIndex;

    public MyQueue(int len) {
        this.len = len;
        value = new int[len];
    }


    public int pull() {
        if (size == 0) {
            throw new RuntimeException("队列已空");
        }
        size--;
        int ele = this.value[pullIndex];
        pullIndex = (pullIndex == (len - 1)) ? 0 : pullIndex + 1;
        return ele;
    }

    public void push(int ele) {
        if (size == len) {
            throw new RuntimeException("队列已满");
        }
        size++;
        this.value[pushIndex] = ele;
        pushIndex = (pushIndex == (len - 1)) ? 0 : pushIndex + 1;
    }


}
